<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    
    <form id="DataForm" action="" method="POST" class="layui-form layui-form-pane">
        <div class="layui-tab layui-tab-brief" lay-filter="itemTab">

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">

                  
                    <div class="layui-form-item">
                        <label class="layui-form-label">省市区</label>
                        <div class="layui-input-inline">
                            <select name="info[province_id]" id="select_0_0" data-id="0" data-num="0"
                                lay-filter="city">
                                <option value="">请选择省</option>
                                {foreach $province as $key=>$val}
                                <option value="{$val.id}">{$val.Name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="info[city_id]" id="select_1_0" data-id="0" data-num="1" lay-filter="city">
                                <option value="">请选择市</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="info[area_id]" id="select_2_0">
                                <option value="">请选择县/区</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">用户账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[usename]" placeholder="请输入用户账号" autocomplete="off"
                                class="layui-input" value="">
                        </div>
                    </div>

                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户昵称</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[title]" placeholder="请输入用户昵称" autocomplete="off"
                                class="layui-input" value="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[password]" placeholder="请输入密码" autocomplete="off"
                                class="layui-input" value="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">用户邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="info[mail]" placeholder="请输入用户邮箱" autocomplete="off"
                                class="layui-input" value="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">用户等级</label>
                        <div class="layui-input-block">
                            <select name="info[level_id]">
                                <option value="0">请选择购买等级</option>
                                {foreach $level as $val}
                                    <option value="{$val.id}">{$val.title}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">保证金</label>
                        <div class="layui-input-block">
                            <input type="number" name="info[margin]" placeholder="请输入保证金" autocomplete="off"
                                class="layui-input" value="">
                        </div>
                    </div>

                    

                    <div class="layui-form-item">
                        <label class="layui-form-label">服务费</label>
                        <div class="layui-input-block">
                            <input type="number" name="info[service_charge]" placeholder="请输入服务费" autocomplete="off"
                                class="layui-input" value="">
                        </div>
                    </div>

                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品分类</label>
                        <div class="layui-input-block">
                            {foreach $cate as $val}
                                <input type="checkbox" name="info[cate_id]" title="{$val['name']}" value="{$val.id}">
                            {/foreach}
                        </div>
                    </div>

                    
                  

                 
                
                  
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:auto;text-align: center;">
                            <button id="saveButton" type="submit" class="layui-btn"><i class="fa fa-check"></i>
                                提交</button>
                            <button id="closeButton" type="button" class="layui-btn layui-btn-primary"><i
                                    class="fa fa-close"></i>
                                关闭</button>
                        </div>
                    </div>
                </div>

              

            </div>
        </div>
    </form>
</div>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
      layui.use(['layer', 'form', 'laydate', 'element', 'upload','tableSelect','wangEditor'], function () {
        var    tableSelect = layui.tableSelect;
        var $ = layui.$, layer = layui.layer, table = layui.table,  element = layui.element,laydate = layui.laydate, form = layui.form, upload = layui.upload;
        var indexFrame = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $("#saveButton").on('click', function () {
            var loading = layer.open({ type: 3 });
            var data = $("#DataForm").serialize()
          
            $.ajax({
                url: "{:url('add')}",
                type: 'post',
                data:data,
                success: function (data) {
                    console.log(data);
                    layer.close(loading);
                    if (data.code == 0) {
                        parent.tableReload();
                        parent.layer.close(indexFrame);
                        parent.layer.msg(data.msg);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            })
            return false;
        })
        upload.render({
                elem: '#upload_image', url: "{:url('common/images')}", done: function (res) {
                        $("#image").val(res.data.name);
                        layer.msg(res.msg);
                }
        });
        $("#closeButton").on('click', function () {
            parent.layer.close(indexFrame);
        })
        
        form.on('select(city)', function (data) {
                var address_id = parseInt($("#" + data.elem.id).attr('data-id'));
                var num = parseInt($("#" + data.elem.id).attr('data-num'));
                var level = 3; //联动级别
                var next = num + 1;
                for (var i = next; i < level; i++) $("option[name='select_" + i + "']").remove();
                if ($('#select_' + num + '_' + address_id).val() != "") {
                    $.post("{:url('common/get_city')}", { id: data.value }, function (data) {
                        for (var i = 0; i < data.length; i++) {
                            var option_str = '<option name="select_' + next + '" value="' + data[i].id + '">' + data[i].Name + '</option>';
                            $('#select_' + next + '_' + address_id).append(option_str);
                        }
                        form.render();
                    });
                }
                form.render();
            });
            var editor_1 = new wangEditor('#editor_1');
            editor_1.customConfig.pasteFilterStyle = false;
            editor_1.customConfig.uploadImgMaxLength = 5;
            editor_1.customConfig.menus = [
                'head',  // 标题
                'bold',  // 粗体
                'fontSize',  // 字号
                'fontName',  // 字体
                'italic',  // 斜体
                'underline',  // 下划线
                'strikeThrough',  // 删除线
                'foreColor',  // 文字颜色
                'backColor',  // 背景颜色
                'link',  // 插入链接
                'list',  // 列表
                'justify',  // 对齐方式
                'table',  // 表格
                'undo',  // 撤销
                'redo'  // 重复
            ];
            editor_1.create();
            });
</script>
</body>
</html>